home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / APXMDIDV.PAK / APXMDDEV.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  134 lines

  1. //----------------------------------------------------------------------------
  2. //  Project ApxMdiDv
  3. //  Borland International
  4. //  Copyright ⌐ 1996. All Rights Reserved.
  5. //
  6. //  SUBSYSTEM:    ApxMdiDv Application
  7. //  FILE:         apxmddev.cpp
  8. //  AUTHOR:       
  9. //
  10. //  OVERVIEW
  11. //  ~~~~~~~~
  12. //  Source file for implementation of TApxMdiDvEditView (TEditView).
  13. //
  14. //----------------------------------------------------------------------------
  15.  
  16. #include <owl/pch.h>
  17.  
  18. #include "apxmddva.h"
  19. #include "apxmddev.h"
  20.  
  21. #include <stdio.h>
  22.  
  23.  
  24. //{{TApxMdiDvEditView Implementation}}
  25.  
  26.  
  27. //
  28. // Build a response table for all messages/commands handled
  29. // by TApxMdiDvEditView derived from TEditView.
  30. //
  31. DEFINE_RESPONSE_TABLE1(TApxMdiDvEditView, TEditView)
  32. //{{TApxMdiDvEditViewRSP_TBL_BEGIN}}
  33.   EV_WM_GETMINMAXINFO,
  34. //{{TApxMdiDvEditViewRSP_TBL_END}}
  35. END_RESPONSE_TABLE;
  36.  
  37.  
  38. //--------------------------------------------------------
  39. // TApxMdiDvEditView
  40. // ~~~~~~~~~~
  41. // Construction/Destruction handling.
  42. //
  43. TApxMdiDvEditView::TApxMdiDvEditView(TDocument& doc, TWindow* parent)
  44. :
  45.   TEditView(doc, parent)
  46. {
  47.   // INSERT>> Your constructor code here.
  48.  
  49. }
  50.  
  51.  
  52. TApxMdiDvEditView::~TApxMdiDvEditView()
  53. {
  54.   // INSERT>> Your destructor code here.
  55.  
  56. }
  57.  
  58.  
  59. //
  60. // Paint routine for Window, Printer, and PrintPreview for a TEditView client.
  61. //
  62. void TApxMdiDvEditView::Paint(TDC& dc, bool, TRect& rect)
  63. {
  64.   TApxMdiDvApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TApxMdiDvApp);
  65.   if (theApp) {
  66.     // Only paint if we're printing and we have something to paint, otherwise do nothing.
  67.     //
  68.     if (theApp->Printing && theApp->Printer && !rect.IsEmpty()) {
  69.       // Use pageSize to get the size of the window to render into.  For a Window it's the client area,
  70.       // for a printer it's the printer DC dimensions and for print preview it's the layout window.
  71.       TSize   pageSize(rect.right - rect.left, rect.bottom - rect.top);
  72.  
  73.       HFONT   hFont = (HFONT)GetWindowFont();
  74.       TFont   font("Arial", -12);
  75.       if (!hFont)
  76.         dc.SelectObject(font);
  77.       else
  78.         dc.SelectObject(TFont(hFont));
  79.  
  80.       TEXTMETRIC  tm;
  81.       int fHeight = dc.GetTextMetrics(tm) ? tm.tmHeight + tm.tmExternalLeading : 10;
  82.  
  83.       // How many lines of this font can we fit on a page.
  84.       //
  85.       int linesPerPage = MulDiv(pageSize.cy, 1, fHeight);
  86.       if (linesPerPage) {
  87.         TPrintDialog::TData& printerData = theApp->Printer->GetSetup();
  88.  
  89.         int maxPg = ((GetNumLines() / linesPerPage) + 1.0);
  90.  
  91.         // Compute the number of pages to print.
  92.         //
  93.         printerData.MinPage = 1;
  94.         printerData.MaxPage = maxPg;
  95.  
  96.         // Do the text stuff:
  97.         //
  98.         int   fromPage = printerData.FromPage == -1 ? 1 : printerData.FromPage;
  99.         int   toPage = printerData.ToPage == -1 ? 1 : printerData.ToPage;
  100.         int   currentPage = fromPage;
  101.         TAPointer<char> buffer = new char[255];
  102.  
  103.         while (currentPage <= toPage) {
  104.           int startLine = (currentPage - 1) * linesPerPage;
  105.           int lineIdx = 0;
  106.           while (lineIdx < linesPerPage) {
  107.             // If the string is no longer valid then there's nothing more to display.
  108.             //
  109.             if (!GetLine(buffer, 255, startLine + lineIdx))
  110.               break;
  111.             dc.TabbedTextOut(TPoint(0, lineIdx * fHeight), buffer, strlen(buffer), 0, 0, 0);
  112.             lineIdx++;
  113.           }
  114.           currentPage++;
  115.         }
  116.       }
  117.     }
  118.   }
  119. }
  120.  
  121.  
  122. void TApxMdiDvEditView::EvGetMinMaxInfo(MINMAXINFO far& minmaxinfo)
  123. {
  124.   TApxMdiDvApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TApxMdiDvApp);
  125.   if (theApp) {
  126.     if (theApp->Printing) {
  127.       minmaxinfo.ptMaxSize = TPoint(32000, 32000);
  128.       minmaxinfo.ptMaxTrackSize = TPoint(32000, 32000);
  129.       return;
  130.     }
  131.   }
  132.   TEditView::EvGetMinMaxInfo(minmaxinfo);
  133. }
  134.